package com.cangshi.controller;

import com.alibaba.fastjson.JSON;
import com.cangshi.entity.*;
import com.cangshi.service.AddressService;
import com.cangshi.service.GoodsTypeService;
import com.cangshi.service.UserPlusInfoService;
import com.cangshi.service.UserService;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
import org.apache.commons.io.FileUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import sun.misc.BASE64Decoder;

import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Random;

/**
 * Created by Eoly on 2016/12/22.
 */

@Controller
public class GoodsTypeController {

    private static final Logger LOGGER = Logger.getLogger(GoodsTypeController.class);

    @Autowired
    GoodsTypeService goodsTypeService;


    /**
     * 根据类型id获取类型
     * @param goodsTypeId
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/group/find-group-type",method = RequestMethod.GET,produces = "text/html;charset=UTF-8")
    public JsonObject findGroupType(@RequestParam Integer goodsTypeId) {
        JsonObject<GoodsType> jsonObject = new JsonObject<GoodsType>();

        //通过指定id 获取团类型
        GoodsType goodsType = goodsTypeService.findByGoodsTypeId(goodsTypeId);

        if(goodsType!=null){
            jsonObject.setError(0);
            jsonObject.setData(goodsType);
            jsonObject.setMes("获取成功");
        }else {
            jsonObject.setError(601);
            jsonObject.setMes("获取失败");
        }

        return jsonObject;
    }

    /**
     * 获取所有类型
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/group/find-all-type",method = RequestMethod.GET,produces = "text/html;charset=UTF-8")
    public JsonObject findAllType() {
        JsonObject<GoodsType> jsonObject = new JsonObject<GoodsType>();

        //通过指定id 获取团类型
        List<GoodsType> goodsTypes = goodsTypeService.findAllGoodsTypes();

        if(goodsTypes!=null){
            jsonObject.setError(0);
            jsonObject.setDataList(goodsTypes);
            jsonObject.setMes("获取成功");
        }else {
            jsonObject.setError(602);
            jsonObject.setMes("获取失败");
        }

        return jsonObject;
    }
}
